package com.example.distinguishcolors.utils;

import android.graphics.Color;

import com.example.distinguishcolors.domain.GameColor;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

/**
 * @author Yingyong Lao
 * 创建时间 2021/10/2 16:12
 * @version 1.0
 */
public class ColorUtils {
    /**
     * 随机生成颜色列表
     * @param dis 差值，范围[1,100]
     * @return 颜色列表
     */
    public static List<GameColor> getRandomColors(int dis){
        List<GameColor> list=new ArrayList<>();
        Random random=new Random();
        int red = random.nextInt(256);
        int green = random.nextInt(256);
        int blue = random.nextInt(256);
        int randomColor1 = Color.argb(255,red,green,blue);
        String colorStr1 = String.format("#%06X", randomColor1);
        GameColor gameColor1 = new GameColor(colorStr1, GameColor.NORMAL);
        for (int i = 0; i < 19; i++) {
            list.add(gameColor1);
        }
        int randomColor2 = Color.argb(255,(red+dis)>255?(red-dis/2):(red+dis),(green+dis)>255?(green-dis/2):(green+dis),(blue+dis)>255?(blue-dis/2):(blue+dis));
        String colorStr2 = String.format("#%06X", randomColor2);
        list.add(new GameColor(colorStr2, GameColor.SPECIAL));
        Collections.shuffle(list);//打乱顺序
        return list;
    }
}
